#include "BlockQueue.h"

void *pRoutine(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    while (1)
    {
        int data = rand() % 1000;
        bq->push(data);
        cout << "生产者生产了数据：" << data << endl;
    }
    return nullptr;
}

void *cRoutine(void *args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int> *>(args);
    while (1)
    {
        int data = -1;
        bq->pop(data);
        cout << "消费者消费了数据：" << data << endl;
        sleep(1);
    }
    return nullptr;
}
int main()
{
    BlockQueue<int> bq(5);
    pthread_t p, c;
    pthread_create(&p, nullptr, pRoutine, &bq);
    pthread_create(&c, nullptr, cRoutine, &bq);
    pthread_join(p, nullptr);
    pthread_join(c, nullptr);
    return 0;
}